package model;

import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class Bar extends GameObject
{
        protected int speedState;
        protected String barType;
        protected boolean visible;
        
        public Bar()
        {
                super();
                xDim = 60;
                yDim = 15;
                speedState = 0;
                barType = "user";
                visible = true;
        }
        
        public Bar(String filename)
        {
                super();
                xDim = 60;
                yDim = 15;
                speedState = 0;
                barType = "user";
                visible = true;
                
                try{
                        image = ImageIO.read(new File(filename));
                } catch(IOException e){ 
                }
        }
        
        public Bar(Bar bar)
        {
                super();
                xDim = 60;
                yDim = 15;
                speedState = bar.getSpeedState();
                visible = bar.getVisibility();
                barType = bar.getType();
                filename = bar.getFilename();
                
                try{
                        image = ImageIO.read(new File(filename));
                } catch(IOException e){ 
                }
        }
        
        public void setType(String str)
        {
                barType = str;
        }
        
        public String getType()
        {
                return barType;
        }
        
        public void setSpeedState()
        {
                speedState = 3;
        }
        
        public int getSpeedState()
        {
                return speedState;
        }
        
        public void setVisibility(boolean v)
        {
                visible = v;
        }
        
        public boolean getVisibility()
        {
                return visible;
        }
        
        public boolean isVisible()
        {
                return visible;
        }
        
        public void setDimY(int y){}
        
        public void draw(Graphics page)
        {
                if(visible)
                        page.drawImage(image, (int)getX(), (int)getY(), null);
        }
        
        public void update(int input)
        {
                if(speedState > 0)
                        speedState--;
                
                if(movable)
                {
                        if(input == KeyEvent.VK_LEFT)
                        {
                                setComponentX(-20);
                                setX(getComponentX() * 0.01);
                                setSpeedState();
                        }
                        else if(input == KeyEvent.VK_RIGHT)
                        {
                                setComponentX(20);
                                setX(getComponentX() * 0.01);
                                setSpeedState();
                        }
                        else
                        {
                                setComponentX(0);
                        }
                }
        }
}